/**
 * 生成视频合并命令
 */

const path = require("path");
const fs = require("fs");
const ffmpegPath = path.join(__dirname , '../', 'ffmpeg', 'ffmpeg.exe');
const cache = path.join(__dirname, "../cache");


function merge_video(meergeFiles, savePath) {

    let mergeFile = path.join(cache, 'merge.txt');

    if (fs.existsSync(mergeFile)) {
        fs.unlinkSync(mergeFile);
    }

    meergeFiles.forEach(filepath => {
        let line = `file '${filepath}'\n`;
        fs.appendFileSync(mergeFile, line, 'utf8');
    })

    let cmdStr = `"${ffmpegPath}" -f concat -safe 0 -i "${mergeFile}" -c copy ${savePath}`;

    return cmdStr;
}

module.exports = merge_video;